/*
 * @Author: your name
 * @Date: 2021-09-03 14:21:09
 * @LastEditTime: 2021-09-03 16:31:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day10\6-原型链继承2.js
 */

//构造函数的属性
function Animal(name, age) {
    this.name = name;
    this.age = age;
}
console.log(Animal); //[Function: Animal]
console.log(Animal.prototype); //{}
console.log(Animal.prototype.constructor); //[Function: Animal]
//构造函数原型的方法
Animal.prototype.sayName = function() {
    console.log(this.name);
}
Animal.prototype = {
    constructor: Animal,
    sayHello: function() {
        console.log(this.name + "say hello");
    }
}
console.log(Animal); //[Function: Animal]
console.log(Animal.prototype); //{ constructor: [Function: Animal], sayHello: [Function: sayHello] }
console.log(Animal.prototype.constructor); //[function:Animal]

function Dog(name, age, color) {
    this.name = name;
    this.age = age;
    this.color = color;
}
console.log(Dog.prototype); //{}
//原型链继承
Dog.prototype = new Animal();
console.log(Dog.prototype); //Animal { name: undefined, age: undefined }

Dog.prototype.constructor = Dog;
Dog.prototype.sayColor = function() {
        console.log(this.color);
    }
    //dog 只是一个对象
var dog = new Dog("金毛", 1, "yellow");
console.log(dog); //Dog { name: '金毛', age: 1, color: 'yellow' }
//sayHello是Animal.prototype的方法
dog.sayHello(); //金毛say hello
//sayColor是Dog.prototype的方法         
dog.sayColor(); //yellow
//toString是Object.prototype的方法
console.log(dog.toString()); //[object Object]

//检测类型
console.log(typeof dog); //object
console.log(dog instanceof Dog); //true
console.log(dog instanceof Animal); //true
console.log(dog instanceof Object); //true
console.log(dog instanceof Date); //false
//检测是否是该原型派生出的对象
console.log(Object.prototype.isPrototypeOf(dog)); //true
console.log(Animal.prototype.isPrototypeOf(dog)); //true
console.log(Dog.prototype.isPrototypeOf(dog)); //true
console.log(Date.prototype.isPrototypeOf(dog)); //false